<!DOCTYPE html>
<!-- saved from url=(0035)http://my.sto.cn/Vip/ForgetPassword -->
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <script type="text/javascript" src="/admin/js/jquery.min.js"></script>
    <script type="text/javascript" src="/home/js/city-picker.data.js"></script>
    <script type="text/javascript" src="/home/js/city-picker.js"></script>


    <link rel="stylesheet" type="text/css" href="/home/userManager/css/common.css">
    <link rel="stylesheet" type="text/css" href="/home/branch/css/city-picker.css">
    <link rel="stylesheet" type="text/css" href="/home/userManager/css/combo.select.css">
    <link rel="stylesheet" type="text/css" href="/home/userManager/css/forgetPassword.css">
    <link rel="stylesheet" type="text/css" href="/home/layui/css/layui.css">


</head>
<body>
<#include "../common/header.ftl">
<#include "../common/top_nav.ftl">
<div class="box" style="min-height:800px;">

    <div class="viewContent">
        <div class="title">
            <div>找回密码</div>
        </div>
        <div class="viewInfo">
            <div class="verifyType">
                <div class="telContent">
                    <div class="fromBox" id="telBox" style="display: block;">
                        <form id="update-password-form" method="post">
                            <p>
                                <label>手机号：</label>
                                <input type="text" class="emaliTxt" id="mobile" name="mobile" value="${homeUser.mobile}" readonly>
                            </p>
                            <p>
                                <label>邮箱：</label>
                                <input type="text" class="emaliTxt" id="email" name="email" value="${homeUser.email}" readonly>
                            </p>
                            <p>
                                <label>验证码：</label>
                                <input type="text" class="verifyTxt" id="code" name="code">
                                <input type="button" class="sendVerifyBox send-code-btn" value="发送验证码"
                                       autocomplete="off">
                                <input type="button" class="sendVerifyBox code-btn" value="重新发送" autocomplete="off"
                                       style="display: none;">
                            </p>
                            <p>
                                <label>新密码：</label>
                                <input type="password" class="emaliTxt" id="password" name="password" placeholder="请输入6-12位密码">
                            </p>
                            <p>
                                <label>确认密码：</label>
                                <input type="password" class="emaliTxt" id="checkPassword" placeholder="请重新输入密码">
                            </p>
                            <p>
                                <a class="nextBtn tel_next" href="javascript:void(0)" id="updatePassword">修改密码</a>
                            </p>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>


</div>

<script type="text/javascript" src="/home/js/layer.js"></script>
<script type="text/javascript" src="/home/layui/layui.all.js"></script>
<script type="text/javascript" src="/home/js/msg.js"></script>
<script>
    //按钮不能连续点击
    var countdown = 60;  // 时长
    function setButton() {
        $(".send-code-btn").hide();
        $(".code-btn").show();
        var timer = setInterval(function () {
            if (countdown == 0) {
                clearInterval(timer);
                $(".send-code-btn").show();
                $(".code-btn").hide();
                countdown = 60;
            }
            $(".code-btn").val('(' + (countdown - 1) + '秒)');
            countdown--;
        }, 1000);
    };

    //验证码发送
    $(".send-code-btn").click(function () {
        var email = $('#email').val();
        if (msg.isEmpty(email)) {
            errorMsg("邮箱为空");
            return;
        }
        if (!msg.isEmail(email)) {
            errorMsg("邮箱格式错误");
            return;
        }
        $.ajax({
            url: '/send_email/generate_code',
            data: {email: email, method: "ylrc_update_password_code"},
            type: 'POST',
            dataType: 'json',
            success: function (data) {
                if (data.code == 0) {
                    successMsg('发送成功注意查收!');
                    setButton();
                } else {
                    errorMsg(data.msg);
                }
            },
            error: function (data) {
                errorMsg("邮箱不存在");
            }
        });
    });


    $("#updatePassword").click(function () {
        var code = $("#code").val();
        var password = $("#password").val();
        var checkPassword = $("#checkPassword").val();
        if (msg.isEmpty(code)) {
            errorMsg("请输入验证码");
            return;
        }
        if (code.length != 4) {
            errorMsg("验证码长度不正确");
            return;
        }
        if (msg.isEmpty(password)) {
            errorMsg("请输入密码");
            return;
        }
        if (msg.isEmpty(checkPassword)) {
            errorMsg("请输入确认密码");
            return;
        }
        if (checkPassword != password) {
            errorMsg("两次密码不一致");
            return;
        }

        var data = $("#update-password-form").serialize();
        $.ajax({
            url: '/home/userManager/updatePassword',
            data: data,
            type: 'POST',
            dataType: 'json',
            success: function (data) {
                if (data.code == 0) {
                    successMsg("修改成功");
                    setTimeout(function () {
                        window.location.href = "/home/userManager/index";
                    }, 1000);
                } else {
                    errorMsg(data.msg);
                }
            }

        });

    });

</script>
</body>
</html>